package pers.liyan.shi.springboot.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import pers.liyan.shi.springboot.entity.User;
import pers.liyan.shi.springboot.repository.UserRepository;

@RestController
public class UserController {

    @Autowired
    UserRepository userRepository;

    //查询
    @GetMapping("/user/{id}")
    public User getUser(@PathVariable("id") Integer id){
        return userRepository.findOne(id);
    }

    @GetMapping("/user")
    public User insertUser(User user){
        return userRepository.save(user);
    }

}
